package com.student.liu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.student.liu.entity.Desk;
import com.student.liu.mapper.ITableMapper;
import com.student.liu.service.ITableService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 用户服务接口 实现类
 */
@Slf4j
@Service
public class TableServiceImpl extends ServiceImpl<ITableMapper, Desk> implements ITableService {

    @Resource
    ITableMapper tableMapper;

    @Override
    public IPage<Map<String, Object>> goodsPage(Integer pageIndex, Integer pageSize, Byte state) {
        Page page = new Page(pageIndex, pageSize);
        QueryWrapper queryWrapper = new QueryWrapper();
        if (state < 2){
        queryWrapper.eq("state" ,state);
        }
        return pageMaps(page,queryWrapper);
    }

    @Override
    public void putOn(Integer id) {
        Desk desk = new Desk();
        desk.setId(id);
        desk.setState((byte) 1);
        updateById(desk);
    }

    @Override
    public void putDown(Integer id) {
        Desk desk = new Desk();
        desk.setId(id);
        desk.setState((byte) 0);
        updateById(desk);
    }

    @Override
    public void createGoods(Desk desk) {
        save(desk);
    }
}
